In [1]:
import matplotlib.pyplot as plt
import numpy as np
import librosa
import IPython.display as ipd

Loading audio files¶

In [2]:
debussy_file = "audio/debussy.wav"
redhot_file = "audio/redhot.wav"
duke_file = "audio/duke.wav"
In [3]:
ipd.Audio(debussy_file)
Out[3]:
Your browser does not support the audio element.
In [4]:
ipd.Audio(redhot_file)
Out[4]:
Your browser does not support the audio element.
In [5]:
ipd.Audio(duke_file)
Out[5]:
Your browser does not support the audio element.
In [6]:
# load audio files with librosa
debussy, sr = librosa.load(debussy_file)
redhot, _ = librosa.load(redhot_file)
duke, _ = librosa.load(duke_file)

Spectral centroid with Librosa¶

In [7]:
FRAME_SIZE = 1024
HOP_LENGTH = 512
In [8]:
sc_debussy = librosa.feature.spectral_centroid(y=debussy, sr=sr, n_fft=FRAME_SIZE, hop_length=HOP_LENGTH)[0]
sc_redhot = librosa.feature.spectral_centroid(y=redhot, sr=sr, n_fft=FRAME_SIZE, hop_length=HOP_LENGTH)[0]
sc_duke = librosa.feature.spectral_centroid(y=duke, sr=sr, n_fft=FRAME_SIZE, hop_length=HOP_LENGTH)[0]
In [9]:
sc_debussy.shape
Out[9]:
(1292,)

Visualising spectral centroid¶

In [10]:
frames = range(len(sc_debussy))
t = librosa.frames_to_time(frames, hop_length=HOP_LENGTH)
In [11]:
len(t)
Out[11]:
1292
In [12]:
plt.figure(figsize=(25,10))

plt.plot(t, sc_debussy, color='b')
plt.plot(t, sc_redhot, color='r')
plt.plot(t, sc_duke, color='y')

plt.show()
No description has been provided for this image

Spectral bandwidth with Librosa¶

In [13]:
ban_debussy = librosa.feature.spectral_bandwidth(y=debussy, sr=sr, n_fft=FRAME_SIZE, hop_length=HOP_LENGTH)[0]
ban_redhot = librosa.feature.spectral_bandwidth(y=redhot, sr=sr, n_fft=FRAME_SIZE, hop_length=HOP_LENGTH)[0]
ban_duke = librosa.feature.spectral_bandwidth(y=duke, sr=sr, n_fft=FRAME_SIZE, hop_length=HOP_LENGTH)[0]
In [14]:
ban_debussy.shape
Out[14]:
(1292,)

Visualising spectral bandwidth¶

In [15]:
plt.figure(figsize=(25,10))

plt.plot(t, ban_debussy, color='b')
plt.plot(t, ban_redhot, color='r')
plt.plot(t, ban_duke, color='y')

plt.show()
No description has been provided for this image
In [ ]: